<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
	<title>Micro Lending Application</title>
	<link rel="stylesheet" type="text/css" href="<c:url value="/static/css/lender.css" />"/>
	<link rel="stylesheet" type="text/css" href="<c:url value="/static/css/jquery.datetimepicker.css" />"/>
	<script type="text/javascript" src="<c:url value="/static/js/vendor/jquery-1.10.2.js" />" ></script>
	<script type="text/javascript" src="<c:url value="/static/js/vendor/jquery.datetimepicker.js" />" ></script>
	<script type="text/javascript" src="<c:url value="/static/js/lender.js" />"></script>
</head>
<body>

	<h2>Micro Lending Application</h2>

	<form:form method="post" action="apply.html" commandName="loan">

		<table>
			<tr>
				<td><form:label path="client.firstname">
						<spring:message code="label.firstname" />
					</form:label></td>
				<td>
					<form:input path="client.firstname" />
				</td>
			</tr>
			<tr>
				<td><form:label path="client.lastname">
						<spring:message code="label.lastname" />
					</form:label></td>
				<td><form:input path="client.lastname" /></td>
			</tr>
			<tr>
				<td><form:label path="client.email">
						<spring:message code="label.email" />
					</form:label></td>
				<td><form:input path="client.email" /></td>
			</tr>
			<tr>
				<td><form:label path="client.telephone">
						<spring:message code="label.telephone" />
					</form:label></td>
				<td><form:input path="client.telephone" /></td>
			</tr>
			<tr>
				<td>
					<form:label path="client.birthDay">
						<spring:message code="label.birthDay" />
					</form:label></td>
				<td>
					<form:input  path="client.birthDay" />
				</td>
			</tr>
			<tr>
				<td><form:label path="client.address">
						<spring:message code="label.address" />
					</form:label></td>
				<td><form:input path="client.address" /></td>
			</tr>
			<tr>
				<td><form:label path="amount">
						<spring:message code="label.amount" />
					</form:label></td>
				<td>
					<form:input path="amount" />
<%-- 					<form:errors path="amount" /> --%>
					<form:errors path="amount" cssClass="error" />
<%-- 					<form:errors/> --%>
				</td>
			</tr>
			<tr>
				<td><form:label path="term">
						<spring:message code="label.term" />
					</form:label></td>
				<td>
					<form:input path="term" />
					<form:errors path="term" cssClass="error" />
				</td>
			</tr>						
			<tr>
				<td colspan="2">
					<input type="submit" value="<spring:message code="label.applyloan"/>" />
					<a href="history"><spring:message code="label.history" /></a>
				</td>
			</tr>
		</table>
	</form:form>


	<c:if test="${!empty client}">
		<h3>Loan History of ${client.firstname} ${client.lastname}</h3>
	</c:if>
	<c:if test="${!empty loanList}">
		<table class="data">
			<tr>
				<th>Reference ID</th>
				<th>Amount</th>
				<th>Term</th>
				<th>Extended?</th>
				<th>&nbsp;</th>
			</tr>
			<c:forEach items="${loanList}" var="loan">
				<tr>
					<td>${loan.referenceId}</td>
					<td>${loan.amount}</td>
					<td>${loan.term}</td>
					
					<c:choose>
						<c:when test="${loan.extendedCount == 0}">
							<td>Not extended yet</td>
						</c:when>
						<c:otherwise>
							<td>${loan.extendedCount} ${loan.extendedCount > 1 ? 'weeks' : 'week' } extended</td>
						</c:otherwise>
					</c:choose>
					
					<td><a href="extend/${loan.referenceId}">extend</a></td>
				</tr>
			</c:forEach>
		</table>
	</c:if>


</body>
</html>
